package com.tangzx.builder.abc;

import com.tangzx.builder.abc.string.AbcString;
import com.tangzx.builder.abc.string.MultiName;
import com.tangzx.builder.abc.string.Namespace;
import com.tangzx.builder.abc.string.NamespaceSet;
import macromedia.asc.util.Decimal128;

public class AbcCPool {
	private int[] ints;
	private long[] uints;
	private double[] doubles;
	private AbcString[] strings;
	private Namespace[] namespaces;
	private NamespaceSet[] namespaceSets;
	private MultiName[] multiNameSet;
	
	public void setIntSet(int[] ints) {
		this.ints = ints;
	}
	
	public int[] getIntSet() {
		return ints;
	}
	
	public int getInt(int index) {
		return ints[index];
	}

	public void setUintSet(long[] uints) {
		this.uints = uints;
	}
	
	public long[] getUintSet() {
		return uints;
	}
	
	public long getUint(int index) {
		return uints[index];
	}

	public void setDoubleSet(double[] doubles2) {
		this.doubles = doubles2;
	}
	
	public double[] getDoubleSet() {
		return doubles;
	}
	
	public double getDouble(int index) {
		return doubles[index];
	}

	public void setDecimalSet(Decimal128[] decimals) {
		//this.decimals = decimals;
	}

	public void setStringSet(AbcString[] strings) {
		this.strings = strings;
	}
	
	public AbcString[] getStringSet() {
		return strings;
	}
	
	public AbcString getString(int index) {
		return strings[index];
	}
	
	public AbcString addNewString(AbcString as)
	{
		AbcString[] newAS = new AbcString[strings.length + 1];
		boolean vaild = true;
		for (int i = 0 ; i < strings.length; i++)
		{
			AbcString str = strings[i];
			if (str.equals(as))
			{
				vaild = false;
				as.index = i;
				break;
			}
			
			newAS[i] = str;
		}
		if (vaild)
		{
			newAS[strings.length] = as;
			as.index = strings.length;
			strings = newAS;
		}
		return as;
	}

	public void setNamespaceSet(Namespace[] namespaces) {
		this.namespaces = namespaces;
		for (Namespace ns : namespaces)
			if (ns != null)
				ns.setCpool(this);
	}
	
	public Namespace getNamespace(int index) {
		return namespaces[index];
	}
	
	public Namespace[] getNamespaceSet() {
		return namespaces;
	}

	public void setMultiNameSet(MultiName[] nameData) {
		this.multiNameSet = nameData;
		for (MultiName nd : nameData)
			if (nd != null)
				nd.setCpool(this);
	}
	
	public MultiName[] getMultiNameSet() {
		return multiNameSet;
	}
	
	public MultiName getMultiName(int index) {
		return multiNameSet[index];
	}

	public void setNamespaceSetSet(NamespaceSet[] namespaceSets) {
		this.namespaceSets = namespaceSets;
		for (NamespaceSet nss : namespaceSets)
			if (nss != null)
				nss.setCpool(this);
	}
	
	public NamespaceSet getNamespaceSet(int index) {
		return this.namespaceSets[index];
	}
	
	public NamespaceSet[] getNamespaceSetSet() {
		return namespaceSets;
	}
}
